import React, { useEffect } from 'react'
import { useLocation, useNavigate } from 'react-router-dom'

function useAuthRoute() {
    const nav = useNavigate()

    const { pathname } = useLocation()
    const token = localStorage.getItem('token')
    const whiteList = ['/layout/role']

    useEffect(() => {
        if(!token&&!whiteList.includes(pathname)) {
            nav('/login')
        }
    }, [])
}

export default useAuthRoute
